package com.example.spring_test2.service;

import com.example.spring_test2.dao.orderDao;
import com.example.spring_test2.domain.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class orderService {
    @Autowired
    orderDao orderdao;

    public void addOrder(Order order){
        if (isExisting(order.getId()))
        {
            System.out.println("该订单已存在，请更换id");
            return;
        }
        orderdao.addOrder(order);
        System.out.println("添加成功");
    }

    public void updateOrder(String status,long id){
        if (!isExisting(id))
        {
            System.out.println("该订单不存在");
            return;
        }
        orderdao.upadteOrder(status,id);
        System.out.println("更改成功");
    }

    public boolean isExisting(long id){
        return orderdao.getOrderById(id) != null;
    }

}
